package com.glsc.ngateway.common.base.repo.mysql.gateway.platform;

import com.glsc.ngateway.common.base.domain.mysql.gateway.platform.Dict;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

/**
 * 功能描述: <br>
 *
 * @author gaojc
 * @date 2020/9/8 17:29
 */
public interface DictRepo extends JpaRepository<Dict, Long>, JpaSpecificationExecutor<Dict> {

    @Query(value = "select d from Dict d where d.dictField= :dictField and d.dictSpace = :dictSpace")
    Dict queryByDictCode(@Param("dictField") String dictField, @Param("dictSpace") String dictSpace);

    @Query(value = "select d from Dict d where d.dictField= :dictField and d.tableName = :tableName")
    Dict queryByFieldName(@Param("dictField") String dictField, @Param("tableName") String tableName);

    @Query(value = "select d from Dict d where d.dictMapId = :dictMapId")
    Dict findById(@Param("dictMapId") long dictMapId);

    @Transactional
    @Modifying
    @Query(value = "delete from Dict d where d.dictMapId = :dictMapId")
    int deleteById(@Param("dictMapId") long dictMapId);
}
